package model

import "fmt"

type Usb interface {
	Start()
	Stop()
}

type Phone struct {
	Name string
}

func (p *Phone) Start() {
	fmt.Println("phone start...")
}

func (p *Phone) Stop() {
	fmt.Println("phone stop....")
}

func (p *Phone) Call() {
	fmt.Println("phone call....")
}

type Cramer struct {
}

func (p *Cramer) Start() {
	fmt.Println("Cramer start...")
}

func (p *Cramer) Stop() {
	fmt.Println("Cramer stop....")
}

//多态，向下转型
func InterfaceConvert() {
	var usb [3]Usb
	var phone = Phone{"xiaomi"}
	usb[0] = &phone
	usb[1] = &Cramer{}
	usb[2] = &Phone{"vivo"}

	for i, _ := range usb {
		usb[i].Start()
		usb[i].Stop()
		p, ok := usb[i].(*Phone)
		if ok {
			p.Call()
		}
	}
}
